package com.kang.config;

import com.kang.interceptor.UserInterceptor;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Component
public class InterceptorConfig implements WebMvcConfigurer {


	@Resource
	private UserInterceptor logInterceptor;

	@Override   // 配置拦截器
	public void addInterceptors(InterceptorRegistry registry) {
		// 对swagger的请求不进行拦截
		String[] excludePatterns = new String[]{"/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**",
				"/api", "/api-docs", "/api-docs/**", "/doc.html/**"};
		registry.addInterceptor(logInterceptor)
				// 拦截所有请求
				.addPathPatterns("/**")
				// 排除指定请求
				.excludePathPatterns(excludePatterns);
	}
}